package com.yonyou.iuap.jxzy.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.java.swing.plaf.windows.resources.windows;
import com.yonyou.iuap.base.web.BaseController;
import com.yonyou.iuap.jxzy.service.IandDFileService;
import com.yonyou.uap.ieop.security.exception.BusinessException;

/**
 * 对已存在文件进行操作
 * @author 21559
 *
 */
@Controller
@RequestMapping(value="/file_operation")
public class FileOperationController extends BaseController{

	@Autowired
	private IandDFileService iandDFileService;
	
	//打包文件
	@RequestMapping(value = "/downf")
	@ResponseBody
	public String downloadImportFile(@RequestParam String tdh,HttpServletRequest request,HttpServletResponse response){
		try {
			iandDFileService.downloadImportFile(tdh,response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	//打包文件
	@RequestMapping(value = "/downfgf")
	@ResponseBody
	public String downloadDomFile(@RequestParam String cph,@RequestParam String xlh,HttpServletRequest request,HttpServletResponse response){
		try {
			if(cph==null && xlh==null){
				//参数为空
				return "操作失败:参数为空";
			}
			iandDFileService.downloadDomFile(cph,xlh,response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return e.getMessage();
		}
		return null;
	}
	
	@RequestMapping(value = "/downfcpbf")
	@ResponseBody
	public String downloadcpbfDomFile(@RequestParam String ds,@RequestParam String de,@RequestParam String bdh,@RequestParam String gys,HttpServletRequest request,HttpServletResponse response){
		try {
			if(ds==null || de==null ){//|| (gys==null && bdh==null)){
				//参数为空
				return "操作失败:参数为空";
			}
			iandDFileService.downloadCPBFFile(ds,de,bdh,gys,response);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return e.getMessage();
		}
		return null;
	}
	
	@RequestMapping(value = "/delf")
	@ResponseBody
	public void FileDel(HttpServletRequest request,HttpServletResponse response){
	
	}
	
}
